<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Admin\Controller;
use Think\Controller;
class RoleController extends Controller {
    function index(){
        $this -> display();
    }

    function showlist(){
        $admin = new \Admin\Model\AdminModel(rule);
        $info = $admin->adminList();
        $this->assign('role',$info);
        $this->display();
    }
	function add(){
		if(empty($_POST)){
			$this->display();
			}else{
				$info = D('Rule')->add($_POST);
				if($info){
					$this->success('添加成功');
					}else{
						$this->error('添加失败');
						}
				}
		}
	function set(){
		if(empty($_POST)){
			 $roleinfo = D('Rule')->find($role_id);
             $this->assign('show',$roleinfo);
            //可供分配的权限信息
             $haveauth = $roleinfo['role-ids'];
             $haveauth = explode(',',$haveauth);
             $this->assign('have',$haveauth);
             $auth_infop = D('Auth')->where("level=0")->select();
	         $auth_infoc = D('Auth')->where("level>0")->select();
             $this->assign('authp',$auth_infop);
             $this->assign('authc',$auth_infoc);
			 $this->display();
			}else{
				 $role = new \Admin\Model\SaveauthModel(Rule);
               $z = $role->SaveAuth($_POST['roleid'],$_POST['auth-id']);
                if($z){
                    $this->success('权限分配成功');
                }else{
                    $this->error('权限分配失败');
                }
				}
		}
	function dele(){
		$where['role_id']=$_GET['id'];
		$dele = D('Rule')->where($where)->delete();
			if($dele){
				$this->success('删除成功');
				}else{
					$this->error('删除失败');
			}
		}
	function update(){
		 if(empty($_POST)){
				$infolist = D('Rule')->select($_GET['id']);
				$this->assign('show',$infolist);
				$this->display();
			}else{
				 $where['role_id'] = $_POST['role_id'];				
				 $data['role_name'] = $_POST['role_name'];
        		 $info = D('Rule')->where($where)->save($data);
				if($info>0){
					$this->success('修改成功');
				}else{
					$this->error('修改失败');
			   }
			}
		}
}

